// page/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    arr: [],
    sysW: null,
    lastDay: null,
    firstDay: null,
    weekArr: ['日', '一', '二', '三', '四', '五', '六'],//
    year: null
  },

  //获取日历相关参数
  dataTime: function () {
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth();
    var months = date.getMonth()+1;

    //获取现今年份
    this.data.year = year;

    //获取现今月份
    this.data.month = months;

    //获取今日日期q
    this.data.getDate = date.getDate();

    //最后一天是几号
    console.log(months)
    var d = new Date(year, months, 0);
    this.data.lastDay = d.getDate();
    console.log(this.data.lastDay)
    //第一天星期几
    let firstDay = new Date(year, month, 1);
    console.log(firstDay)
    this.data.firstDay = firstDay.getDay();
    console.log()
  },
  dataTime1: function (year,month,months) {
    var date = new Date();
    var year = year;
    var month =month;
    var months = months;

    //获取现今年份
    this.data.year = year;

    //获取现今月份
    this.data.month = months;

    //获取今日日期q
    this.data.getDate = date.getDate();

    //最后一天是几号
    console.log(months)
    var d = new Date(year, months, 0);
    this.data.lastDay = d.getDate();
    console.log(this.data.lastDay)
    //第一天星期几
    let firstDay = new Date(year, month, 1);
    console.log(firstDay)
    this.data.firstDay = firstDay.getDay();
    console.log()
  },
  onShow:function(){
    //拿到星期几，根据第一天星期几来判
    console.log(new Date('2018-08-31').getDay())
  },
  onLoad: function (options) {
    //第一天星期几，必须要知道月份,年
    this.dataTime1(2018,8,9);
    //根据得到今月的最后一天日期遍历 得到所有日期
    for (var i = 1; i < this.data.lastDay + 1; i++) {
      let dd={}
      dd.i=i;
      if(i===2){
        dd.i='START'
      }else if(i===21){
        dd.i='FINISH'
      }else if(i>21){
        //在周期外面
        dd.isNoAction=true
      }else if(i>this.data.getDate){
        //在周期内未打卡空心
        dd.isNe=true
      }
      //让好友助力打卡
      if(i===3){
        dd.isNo=true
      }
      //有奖品
      if(i===14){
        dd.isPrize=true
      }
      
      this.data.arr.push(dd);
      
    }
    var res = wx.getSystemInfoSync();
    console.log(res)
    let windowHeight
    if (res.model === 'iPhone X') {
      windowHeight=600
    }else{
      windowHeight = res.windowHeight
    }
    console.log(windowHeight / 12)
    console.log(this.data.firstDay)
    var aa = [{ year: '2018-08-28', i: 28 },{ year: '2018-08-29', i: 29 },{ year: '2018-08-30', i: 30 },{ year: '2018-08-31', i: 31 }]
    let cc= aa.concat(this.data.arr)
    cc = cc.concat([{ i: 1 }, { i: 2 }])
    this.setData({
      sysW: windowHeight / 12,//更具屏幕宽度变化自动设置宽度
      marLet: 2,//星期几，用于判断移位
      arr: cc,//日期数组
      year: this.data.year,//年
      getDate: this.data.getDate,//当前日期
      month: this.data.month//月
    });
  }
})